package com.ruoyi.project.cyq.item.archiving.service;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.cyq.item.archiving.domain.Archiving;
import com.ruoyi.project.cyq.item.archiving.domain.ArchivingVo;
import com.ruoyi.project.cyq.item.archiving.mapper.ArchivingMapper;
import com.ruoyi.project.cyq.order.domain.OrderProduct;
import com.ruoyi.project.cyq.order.mapper.OrderProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.List;

/**
 * @author Strawberry
 * @date 2020-09-18 下午 3:53
 * @desc 快乐将永远依着草莓
 * @desc 项目资料归档管理service接口的实现类
 */
@Service
public class ArchivingServiceImpl implements IArchivingService {

    @Autowired
    private ArchivingMapper archivingMapper;

    /**
    * 某大神的orderProduct没有service，只能自己来一个了
    * */
    @Autowired
    private OrderProductMapper orderProductMapper;


    /**
     * 查询所有审核项目
     */
    @Override
    public List<Archiving> selectAllArchiving(ArchivingVo archiving) {
        return archivingMapper.selectAllArchiving(archiving);
    }

    /**
     * 通过projectId查询一个项目
     */
    @Override
    public ArchivingVo selectOneById(BigInteger projectId) {
        return archivingMapper.selectOneById(projectId);
    }


    /**
     * 更新审核结果
     */
    @Override
    public int updateArchivingResult(Archiving archiving) {
        archiving.setReviewReviewer(ShiroUtils.getLoginName());
        return archivingMapper.updateArchivingResult(archiving);
    }

    /**
     * 新增一个项目审核
     */
    @Override
    public int addNewArchiving(BigInteger itemId, BigInteger staffId) {
        System.out.println(itemId + " : " + staffId);
        Archiving archiving = new Archiving();
        archiving.setProjectId(itemId);
        archiving.setStaffId(staffId);
        System.out.println("ArchivingServiceImpl--addNewArchiving--archiving ==> " + archiving);
        int addResult = archivingMapper.addNewArchiving(archiving);
        return addResult;
    }

    /**
     * 通过id查询订单产品
     * */
    @Override
    public OrderProduct selectProjectById(Long productId) {
        return orderProductMapper.selectByProductId(productId);
    }


}
